|
1
|
|
|
'use strict' |
|
2
|
|
|
|
|
3
|
|
|
import './types/email' |
|
4
|
|
|
import { authenticable } from './models/authenticable' |
|
5
|
|
|
import { confirmable } from './models/confirmable' |
|
6
|
|
|
import { lockable } from './models/lockable' |
|
7
|
|
|
import { recoverable } from './models/recoverable' |
|
8
|
|
|
import { registerable } from './models/registerable' |
|
9
|
|
|
import { trackable } from './models/trackable' |
|
10
|
|
|
|
|
11
|
|
|
let options = {} |
|
12
|
|
|
|
|
13
|
|
|
export function devise (schema, opts) { |
|
14
|
|
|
options = Object.assign({ |
|
15
|
|
|
confirmable: { |
|
16
|
|
|
tokenLifeSpan: 3 |
|
17
|
|
|
}, |
|
18
|
|
|
lockable: { |
|
19
|
|
|
tokenLifeSpan: 3, |
|
20
|
|
|
maximumAllowedFailedAttempts: 3 |
|
21
|
|
|
}, |
|
22
|
|
|
recoverable: { |
|
23
|
|
|
tokenLifeSpan: 3 |
|
24
|
|
|
}, |
|
25
|
|
|
registerable: { |
|
26
|
|
|
autoConfirm: false |
|
27
|
|
|
} |
|
28
|
|
|
}, opts) |
|
29
|
|
|
|
|
30
|
|
|
/* |
|
31
|
|
|
* format the string with the past values |
|
32
|
|
|
*/ |
|
33
|
|
|
function stringFormat (key, values) { |
|
34
|
|
|
let message = options[key] |
|
35
|
|
|
if (values) { |
|
36
|
|
|
Object.keys(values).forEach(param => { |
|
37
|
|
|
message = message.replace(`{{${param}}}`, values[param]) |
|
38
|
|
|
}) |
|
39
|
|
|
} |
|
40
|
|
|
return message |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/* |
|
44
|
|
|
* implementation of translator method |
|
45
|
|
|
*/ |
|
46
|
|
|
function t (key, values) { |
|
47
|
|
|
return options.i18n |
|
48
|
|
|
? options.i18n.t(key, values) |
|
49
|
|
|
: stringFormat(key, values) |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/* |
|
53
|
|
|
* implementation of notification send |
|
54
|
|
|
*/ |
|
55
|
|
|
function sendNotification (record, action, done) { |
|
56
|
|
|
done() |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
schema.methods.sendNotification = schema.methods.send || sendNotification |
|
60
|
|
|
|
|
61
|
|
|
// i18n adapter methodos |
|
62
|
|
|
schema.methods.t = schema.methods.t || t |
|
63
|
|
|
schema.statics.t = schema.statics.t || t |
|
64
|
|
|
|
|
65
|
|
|
authenticable(schema, options) |
|
66
|
|
|
confirmable(schema, options) |
|
67
|
|
|
lockable(schema, options) |
|
68
|
|
|
recoverable(schema, options) |
|
69
|
|
|
registerable(schema, options) |
|
70
|
|
|
trackable(schema) |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
export default devise |
|
74
|
|
|
|